package com.xzakota.minesweeper.msg;

import com.xzakota.minesweeper.model.entity.UserBean;

/**
 * 聊天消息
 *
 * @author Xzakota
 */
public class ChatMsg extends BaseMsg implements IUserMsg {
    @Override
    public UserBean getUser() {
        UserBean user = null;
        Object[] msg = (Object[]) this.data;
        if (msg[0] instanceof UserBean) {
            user = (UserBean) msg[0];
        }
        return user;
    }

    public String getChat() {
        Object[] msg = (Object[]) this.data;
        String chat = null;
        if (msg[1] instanceof String) {
            chat = (String) msg[1];
        }
        return chat;
    }

    @Override
    public String getTag() {
        return "聊天消息";
    }

    @Override
    public String toString() {
        String username = "系统";
        if (getUser() != null) {
            username = getUser().username;
        }
        return getTag() + ": " + username + ": " + getChat();
    }
}